# -*- coding: utf-8 -*-
"""
Production Environment Settings

Configuration for production environment with security and performance optimizations.
"""

from typing import List
from pydantic import Field
from .base import BaseSettings


class ProductionSettings(BaseSettings):
    """
    Production environment configuration
    
    Optimized for production with security and performance features.
    """
    
    environment: str = Field(default="production", description="Environment name")
    
    # Debug Configuration - Disabled in production
    debug: bool = Field(default=False, description="Disable debug mode")
    reload: bool = Field(default=False, description="Disable auto-reload")
    
    # API Configuration
    api_host: str = Field(default="0.0.0.0", description="API host")
    api_port: int = Field(default=8004, description="API port")
    
    # CORS - Stricter for production
    cors_origins: List[str] = Field(
        default=[],  # Should be set via environment variables
        description="Allowed CORS origins (must be explicitly set)"
    )
    
    # Logging - Production level
    log_level: str = Field(default="INFO", description="Logging level")
    log_file: str = Field(
        default="/var/log/redfire/market_data_service.log",
        description="Log file path"
    )
    
    # Cache - Longer TTL for production
    cache_l1_ttl: int = Field(default=300, description="L1 cache TTL (5 min)")
    cache_l2_ttl: int = Field(default=1800, description="L2 cache TTL (30 min)")
    cache_l3_ttl: int = Field(default=3600, description="L3 cache TTL (1 hour)")
    
    # Database - Production instances (must be set via env vars)
    influxdb_url: str = Field(
        default="http://influxdb:8086",
        description="InfluxDB URL"
    )
    influxdb_token: str = Field(
        default="",  # Must be set via environment variables
        description="InfluxDB token (REQUIRED in production)"
    )
    influxdb_org: str = Field(
        default="redfire_org",
        description="InfluxDB organization"
    )
    influxdb_bucket: str = Field(
        default="redfire_bucket_prod",
        description="InfluxDB bucket (production)"
    )
    
    redis_host: str = Field(
        default="redis",  # Docker service name
        description="Redis host"
    )
    redis_port: int = Field(default=6379, description="Redis port")
    redis_password: str = Field(
        default="",  # Should be set via environment variables
        description="Redis password (RECOMMENDED in production)"
    )
    redis_db: int = Field(default=1, description="Redis database")
    
    # Resilience - Stricter for production
    resilience_cb_failure_threshold: int = Field(
        default=5,
        description="Circuit breaker failure threshold"
    )
    resilience_rate_limit_requests: int = Field(
        default=100,
        description="Rate limit for production"
    )
    
    # Monitoring - Standard intervals
    monitoring_check_interval: float = Field(
        default=60.0,
        description="Health check interval"
    )
    monitoring_metrics_interval: float = Field(
        default=30.0,
        description="Metrics collection interval"
    )
    
    # Performance - Larger pools for production
    worker_pool_size: int = Field(
        default=8,
        description="Worker pool size for production"
    )
    max_concurrent_requests: int = Field(
        default=20,
        description="Higher concurrency for production"
    )
    
    # Data retention - Full retention
    data_retention_days: int = Field(
        default=365,
        description="365 days retention for production"
    )
    
    # Batch size - Larger for production
    batch_size: int = Field(
        default=5000,
        description="Larger batch size for production"
    )
    
    class Config:
        env_prefix = "PROD_"
        env_file = ".env.production"
        env_file_encoding = "utf-8"
        case_sensitive = False
        extra = "ignore"

